// lib/src/utils/localization_util.dart

import 'package:flutter/widgets.dart';

class OmniLocalizations {
  final Locale locale;

  OmniLocalizations(this.locale);

  static final Map<String, Map<String, dynamic>> _localizedValues = {
    'en': {
      'weekdays': ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
      'lunar': 'Lunar',
      'start': 'Start',
      'end': 'End',
      'year_month_format': (int year, int month) => '${_getEnMonth(month)} $year',
      'date_format': (DateTime date) {
        final weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
        return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')} ${weekdays[date.weekday % 7]}';
      }
    },
    'zh': {
      'weekdays': ['日', '一', '二', '三', '四', '五', '六'],
      'lunar': '农历',
      'start': '开始',
      'end': '结束',
      'year_month_format': (int year, int month) =>
      '${year}年${month.toString().padLeft(2, '0')}月',
      'date_format': (DateTime date) {
        final weekdays = ['日', '一', '二', '三', '四', '五', '六'];
        return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}  星期${weekdays[date.weekday % 7]}';
      }
    },
  };

  static String _getEnMonth(int month) {
    return [
      'January', 'February', 'March', 'April', 'May', 'June', 'July',
      'August', 'September', 'October', 'November', 'December'
    ][month - 1];
  }

  Map<String, dynamic> get _values =>
      _localizedValues[locale.languageCode] ?? _localizedValues['en']!;

  List<String> get weekdays => _values['weekdays'];
  String get lunarLabel => _values['lunar'];
  String get startLabel => _values['start'];
  String get endLabel => _values['end'];
  String getYearMonth(int year, int month) => _values['year_month_format'](year, month);
  String getFormattedDate(DateTime date) => _values['date_format'](date);

  bool get isChinese => locale.languageCode == 'zh';
}
